package project.controller;
import org.json.JSONObject;
import project.dao.ProjectDao;
import user.dao.UserDao;
import project.entity.Project;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ProjectUpdateServlet extends HttpServlet {
    private final ProjectDao projectDao = new ProjectDao();
    private static final long serialVersionUID = 1;

    public ProjectUpdateServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        System.out.println("进入了ProjectUpdateServlet");
        Project project = new Project();

        project.setId(Integer.parseInt(request.getParameter("id")));
        project.setLeader(request.getParameter("leader"));
        project.setProjectName(request.getParameter("projectName"));
        project.setDetail(request.getParameter("detail"));
        System.out.println(project);
        projectDao.updateProject(project);
        System.out.println("执行了项目更新!");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",200);
        jsonObject.put("message","项目信息更新成功");
        System.out.println(jsonObject.toString());
        response.getWriter().write(jsonObject.toString());
    }
}
